<template>
  <div v-if="isVisible" class="modal-backdrop">
    <div class="modal-content">
      <h3>取消订单退款规则</h3>
      <p class="refund-rules">{{ refundRules }}</p>
      <div class="checkbox-container">
        <input type="checkbox" id="acknowledge-refund" v-model="acknowledged" />
        <label for="acknowledge-refund">我已了解退款条款</label>
      </div>
      <div class="modal-actions">
        <button @click="confirmAction" :disabled="!acknowledged" class="confirm-button">确定</button>
        <button @click="cancelAction" class="cancel-button">取消</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue';

const props = defineProps({
  isVisible: {
    type: Boolean,
    default: false
  },
  refundRules: {
    type: String,
    required: true
  }
});

const emit = defineEmits(['confirm', 'cancel']);

const acknowledged = ref(false);

// Reset acknowledged state when modal visibility changes
watch(() => props.isVisible, (newVal) => {
  if (newVal) {
    acknowledged.value = false;
  }
});

const confirmAction = () => {
  if (acknowledged.value) {
    emit('confirm');
  }
};

const cancelAction = () => {
  emit('cancel');
};
</script>

<style scoped>
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background-color: #fff;
  padding: 2rem;
  border-radius: 10px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 500px;
  text-align: center;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

h3 {
  color: #0056b3;
  margin-bottom: 1.5rem;
  font-size: 1.5rem;
}

.refund-rules {
  white-space: pre-wrap; /* Preserves line breaks */
  text-align: left;
  margin-bottom: 1.5rem;
  color: #555;
  line-height: 1.6;
}

.checkbox-container {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2rem;
}

.checkbox-container input[type="checkbox"] {
  margin-right: 0.8rem;
  width: 1.2rem;
  height: 1.2rem;
  cursor: pointer;
}

.checkbox-container label {
  font-size: 1.1rem;
  color: #333;
  cursor: pointer;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.modal-actions button {
  padding: 0.8rem 1.8rem;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background-color 0.3s ease, opacity 0.3s ease;
}

.confirm-button {
  background-color: #28a745;
  color: white;
}

.confirm-button:hover:not(:disabled) {
  background-color: #218838;
}

.confirm-button:disabled {
  background-color: #cccccc;
  cursor: not-allowed;
  opacity: 0.7;
}

.cancel-button {
  background-color: #dc3545;
  color: white;
}

.cancel-button:hover {
  background-color: #c82333;
}
</style>
